{% extends 'base.html' %}
{% load static %}
{% block title %}
    天天生鲜-登录
{% endblock title %}

{% block topfiles %}
    <script type="text/javascript" src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
{% endblock topfiles %}
{% block header_con %}
{% endblock header_con %}
{% block search_bar %}
{% endblock search_bar %}
{% block body %}
    <div class="login_top clearfix">
        <a href="index.html" class="login_logo"><img src="{% static 'images/logo02.png' %}"></a>
    </div>
    <div class="login_form_bg">
        <div class="login_form_wrap clearfix">
            <div class="login_banner fl"></div>
            <div class="slogan fl">日夜兼程 · 急速送达</div>
            <div class="login_form fr">
                <div class="login_title clearfix">
                    <h1>用户登录</h1>
                    <a href="/user/register/">立即注册</a>
                </div>
                <div class="form_input">
                    <form id="login_form">
                        {% csrf_token %}
                        <input type="text" name="username" class="name_input" value="{{ username }}"
                               placeholder="请输入用户名">
                        <div class="user_error">输入错误</div>
                        <input type="password" name="pwd" class="pass_input" placeholder="请输入密码">
                        <div class="pwd_error">输入错误</div>
                        <div class="more_input clearfix">
                            <input type="checkbox" {{ checked }} name="remember">
                            <label>记住用户名</label>
                            <a href="#">忘记密码</a>
                        </div>
                        <input type="button" id="login_btn" name="" value="登录" class="input_submit">
                        <div class="button_error">输入错误</div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock body %}
{% block bottomfile %}
    <script type="text/javascript">
    $(function () {
        console.log(window.location);
        $('#login_btn').on('click', function () {
            $('.button_error').html('').hide();
            $('.user_error').html('').hide();
            $('.pwd_error').html('').hide();
            $.ajax({
                type: 'post',
                url: window.location.pathname + window.location.search,
                data: $('#login_form').serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        window.location.href = data.data[0].next
                    } else {
                        if (data.msg == '数据不完整' || data.msg == '账号未激活') {
                            $('.button_error').html(data.msg).show();
                        }
                        if (data.msg == '用户不存在') {
                            $('.user_error').html(data.msg).show();
                        }
                        if (data.msg == '密码不正确') {
                            $('.pwd_error').html(data.msg).show();
                        }
                    }


                }
            })
        })
    })
</script>
{% endblock bottomfile %}